package com.ljx.offer;

import java.util.LinkedList;
import java.util.List;

/**
 * @author 李捷禧
 * Date: 2023/3/18
 * ClassName: C_55
 */

public class C_55 {
    private  List<List<Integer>> lists;
    /**
     * 使用32题的解题思路
     * 代码基本一样
     * @param root
     * @return
     */
    public int maxDepth(TreeNode root) {
        lists = new LinkedList<>();
        return isNum(0,root);
    }

    private int isNum(int depth, TreeNode root) {
        if(root == null) return 0;
        if(depth == lists.size()) lists.add(new LinkedList<>());
        lists.get(depth).add(root.val);
        isNum(depth + 1,root.left);
        isNum(depth + 1,root.right);
        return lists.size();
    }

    class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x; }
    }

}
